package tests.jdl.databaseObjects;

import jdl.databaseObjects.DbField;
import jdl.databaseObjects.DbType;
import jdl.databaseObjects.FieldCollection;
import jdl.databaseObjects.ObjectAlreadyExistsException;
import jdl.databaseObjects.Table;
import junit.framework.Assert;

import org.junit.Test;
import org.mockito.Mockito;

public class Table_Test {
	@Test
	public void getName() {
		Table table = new Table("qwerty");
		Assert.assertEquals("qwerty", table.getName());
	}

	@Test
	public void getFieldCollection_FieldCountIsZero() {
		Table table = new Table("qwerty");
		FieldCollection fieldCollection = table.getFieldCollection();
		Assert.assertEquals(0, fieldCollection.getCount());
		Assert.assertEquals(table, fieldCollection.getTable());
	}

	@Test
	public void addField() throws ObjectAlreadyExistsException {
		Table table = new Table("hello");
		DbType type = Mockito.mock(DbType.class);
		DbField field = new DbField("id", type);
		table.addField(field);
		FieldCollection collection = table.getFieldCollection();
		Assert.assertEquals(1, collection.getCount());
		Assert.assertEquals(field, collection.getObjectByIndex(0));
	}
}
